<?php
if(!function_exists('precisionRestore')){
    function precisionRestore($one,$two,$type){
        $one = (double)$one;
        $two = (double)$two;
        $one_dec = sum_length($one);
        $two_dec = sum_length($two);
        $sum = '';
        if($one_dec>$two_dec){
            $dec = $one_dec;
        }else{
            $dec = $two_dec;
        }
        $ten = pow(10,$dec);
        switch ($type) {
            case '加法':
                $sum = ($one*$ten + $two*$ten) / $ten;
                break;
            case '减法':
                $sum = ($one*$ten - $two*$ten) / $ten;
                break;
            case '乘法':
                $sum = (($one*$ten) * ($two*$ten)) / pow($ten,2);
                break;
            case '除法':
                if(($two*$ten) == 0){
                    $sum = '0';
                }else{
                    $sum = ($one*$ten) / ($two*$ten);
                }
                break;
            default:
                return '参数错误';
        }
        return (string)$sum;
    }
    function sum_length($num) {
        $count = 0;
        $temp = explode('.',$num);
        if (sizeof($temp) > 1) {
            $decimal = end($temp);
            $count = strlen($decimal);
        }
        return $count;
    }
}

if(!function_exists('dateWithinThisWeek')){
    function dateWithinThisWeek($date){
        $dateToCheck = new \DateTime($date); // 假设我们要检查的日期
        $currentWeekStart = new \DateTime('now'); // 获取当前周的起始日
        // 将日期设置为周一作为一周的开始（如果需要周日作为开始，则使用 'P1W T0H0M0S'）
        $currentWeekStart->modify('last Monday');
        $currentWeekEnd = (clone $currentWeekStart)->modify('+6 days'); // 获取当前周的结束日
        // 检查日期是否在当前周内
        if ($dateToCheck >= $currentWeekStart && $dateToCheck <= $currentWeekEnd) {
            echo true;
        } else {
            echo false;
        }
    }
}
if(!function_exists('dateWeek')){
    function dateWeek($date){
        $dt = new \DateTime($date);
        $dayOfWeek = $dt->format('N'); // 获取数字表示的星期几（1-7）
        $arr = [
            1 => '一',
            2 => '二',
            3 => '三',
            4 => '四',
            5 => '五',
            6 => '六',
            7 => '天'
        ];
        return '周'.$arr[$dayOfWeek];
    }
}
if(!function_exists('getWeekDay')){
    function getWeekDay($time){
        $week_array = array('天','一','二','三','四','五','六');
        $week = date('w',strtotime($time));
        return "周".$week_array[$week];
    }
}